
function statusPrint(msg){
	var elStatus = document.getElementById('status_text');
	elStatus.innerHTML = msg;
}

function syncVal(dbVariable,dbKey,elementID){

	var elDebug = document.getElementById('debug_text');

	var valElement = document.getElementById(elementID)

	if(valElement.type == 'checkbox'){
		if(valElement.checked){
			var newvalue = '1';
		}
		else{
			var newvalue = '0';
		}
	}
	else{
		var newvalue = valElement.value;
	}

	var oldValElID = 'OV_' + elementID;
	var oldvalue = document.getElementById(oldValElID).value;
	
	elDebug.innerHTML = "Variable = " + dbVariable + " And key(s) = " + dbKey + " and changeElName = " + elementID + " newvalue= " + newvalue + " FROM: " + oldvalue + 'ELtype= ' + valElement.type;

// set key value (now done in global in top )
//	var keyvariables = 'EmployeeNumber';
	
// get value from db
	//-DO ON SERVER SIDE
// compare old value and db value

// if same, send new value for update

	params_sreqheader = "rqkeyvalues=" + escape(dbKey) + "&mode=update&var=" + escape(dbVariable) + "&value=" + escape(newvalue) + "&rqkeyvariables=" + escape(keyvariables);
	//span_s_req_id.innerHTML += "IN AGAIN";
	//span_s_req_id.innerHTML += "params=  " + params_sreqheader; 
	
	var request_s = YAHOO.util.Connect.asyncRequest('POST', url_syncval, cb_do_syncval, params_sreqheader); 
	
	cb_do_syncval.argument.target = elementID;
	cb_do_syncval.argument.newvalue = newvalue;
	cb_do_syncval.argument.oldvalue = oldvalue;

// else, give error

// Also, give error on communciations failure

}


// Callback handlers for display of requirements drop_down
var handle_succ_syncval = function(o){

	
	if(o.responseText !== undefined){
						 
		result_text = o.responseText;
		el_Item = document.getElementById(o.argument.target);
		el_OldItem = document.getElementById('OV_' + o.argument.target);		
//		var elDebug = document.getElementById('debug_text');
		
//		elDebug.innerHTML += "THEARGTARGET=" + o.argument.target;

		if(result_text == 'Success'){
			
		
			el_OldItem.value = o.argument.newvalue;
			}
		else{
			statusPrint("<b>Error - changes not changed to DB</b>");
			
			if(el_Item.type == 'checkbox'){
				if(o.argument.oldvalue == 0){
					el_Item.checked = false;
				}
				else{
					el_Item.checked = true;
				}
			}
			else{
				el_Item.value = o.argument.oldvalue;
			}
		}
		
//		elDebug.innerHTML += result_text;

	}
}

var handle_fail_syncval = function(o){
	el = document.getElementById(o.argument.target);
	el.innerHTML = "Failed data retrieve";
	}


var cb_do_syncval =
{
  success: handle_succ_syncval,
  failure: handle_fail_syncval,
  argument: { target:"foo", bar:"bar" }
};	



function chg_discipline_id()
{
  document.myform.submit();
}

	function ApplyFieldBoxes()
	{
		usecomma = false;
		seltrans = document.getElementById('seltrans');
		//seltrans.value += 'Running';
		for(i=0; i<document.forms.length; i++)
		{
		//seltrans.value += 'inform';
			for(j=0; j<document.forms[i].elements.length; j++)
			{
			//seltrans.value += 'in type= ' += document.forms[i].elements[j].type;
			//seltrans.value += 'In name:' ;
			//seltrans.value += document.forms[i].elements[j].name;
				if(document.forms[i].elements[j].type=="checkbox"){
				//seltrans.value += 'In name:' ;
				//seltrans.value += document.forms[i].elements[j].name;		
					if((document.forms[i].elements[j].name=="addtochecked") && (document.forms[i].elements[j].checked)) {
						//seltrans.value += "THIS ONE IS CHECKED OF A KEY";
						if(usecomma){
						seltrans.value += ";";
						}
						seltrans.value += document.forms[i].elements[j].value;
						usecomma = true;
				
					}
				}
			
			}
		}
	
	}		
	
function select_all()
{
for(i=0; i<document.forms.length; i++)
		{
		for(j=0; j<document.forms[i].elements.length; j++)
			{
				if(document.forms[i].elements[j].type=="checkbox"){
					if(document.forms[i].elements[j].name=="addtochecked") {
						//seltrans.value += document.forms[i].elements[j].value + ", ";
						document.forms[i].elements[j].checked = true;
					}
				}
			
			}
		}

}

function unselect_all()
{
for(i=0; i<document.forms.length; i++)
		{
		for(j=0; j<document.forms[i].elements.length; j++)
			{
				if(document.forms[i].elements[j].type=="checkbox"){
					if(document.forms[i].elements[j].name=="addtochecked") {
						//seltrans.value += document.forms[i].elements[j].value + ", ";
						document.forms[i].elements[j].checked = false;
					}
				}
			
			}
		}

}		
